home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Bradd W. Szonye <bradds@ix.netcom.com>
- Newsgroups: comp.lang.c++
- Subject: RE: int::~int()
- Date: 20 Apr 1996 16:36:27 GMT
- Organization: Netcom
- Message-ID: <01bb2ed7.f7cd64e0$65c2b7c7@Zany.localhost>
- References: <317083F7.116E@public.sta.net.cn> <marnoldDpuDu9.D7s@netcom.com>
- NNTP-Posting-Host: det-mi3-05.ix.netcom.com
- X-NETCOM-Date: Sat Apr 20 11:36:27 AM CDT 1996
- X-Newsreader: Microsoft Internet News
-
-
- On Sunday, April 14, 1996, Matt Arnold wrote...
- > Xu Yifeng <jafd@public.sta.net.cn> writes:
- >
- > >Hi everybody,
- >
- > >can your compiler compile following program?
- >
- > >//------------------------
- > >void main()
- > >{
- > > int i = 0;
- >
- > > i.int::~int();
- > >}
- > >//------------------------
- >
- > >is it a legal C++ program?
- >
- > It's supposed to be, but most C++ compiler's will not compile it.
- >
- > In fact, this exact sitution is encountered in the Standard Template
- > Library (STL), which contains the following template function...
- >
- > template <class T>
- > inline void destroy(T* pointer) {
- > pointer->~T();
- > }
- >
- > ...which is supposed to be used to destroy anything, including an
- > instance of an int, just like your sample code wants to.
- >
- > To make STL work with current compilers, you'll find it also contains
- > work-around versions of destroy(). There's one specifically for int,
- > and it looks like this...
- >
- > inline void destroy(int*) {}
- >
- > ...which is what the template version is supposed to do; nothing. STL
- > contains about 50 or so of these specific versions of destroy() (for
- > ints, chars, floats, etc.).
- >
- > You sample code is legal as far as the language goes, but probably
- > not as far as your compiler is concerned. Mine, Borland C++ 4.52,
- > will not compile it either. However, I think Borland C++ 5.0 will.
- >
-
- This is just another good reason to rely on your compiler's manuals and
- observing actual program behavior rather than relying on a standards
- document. Especially with an evolving language like C++, you can't always
- rely on the standards.
-
-
-